package com.hdoit.ares.web.tp.zzb.apis;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hdoit.ares.logical.tp.zzb.model.Tomeasure;
import com.hdoit.ares.selfcommon.enums.tp.ComState;
import com.hdoit.ares.selfcommon.thirdparty.zzb.service.IZzbService;
import com.hdoit.ares.selfcommon.thirdparty.zzb.utils.RC4Util;
import com.hdoit.ares.selfcommon.thirdparty.zzb.utils.ZzbConfiguration;
import com.hdoit.ares.selfcommon.thirdparty.zzb.utils.ZzbManageContainer;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.component.webapi.BaseApi;
import com.tennetcn.component.webapi.ResponseModel;
import com.xiaoleilu.hutool.util.RandomUtil;

@Controller
@RequestMapping(value = "/api/v1/zzbAres/",method = {RequestMethod.GET,RequestMethod.POST},produces="application/json;charset=utf-8")
@Api(value="/api/v1/zzbAres/")
@CrossOrigin(origins = "*",maxAge = 3600)
public class ZzbAresApi extends BaseApi{
	
	private IZzbService zzbService;
	
	public IZzbService getZzbService() {
		return zzbService;
	}
	@Resource
	public void setZzbService(IZzbService zzbService) {
		this.zzbService = zzbService;
	}

	private final String toFanhuaCarApi="toFanhuaCar";
	private final String toZhonganCarApi="toZhonganCar";
	private final String tofanhuaAccidentApi="toFanhuaAccident";
/*	private final String tomeasureApi="tomeasure";*/
	
	@ResponseBody
	@RequestMapping(value = toFanhuaCarApi)
	@ApiOperation(notes= toFanhuaCarApi,httpMethod = "POST" ,value = "泛华车险详情访问授权")
	public String toFanhuaCar(){
		
		ResponseModel rm = new ResponseModel();
		String custId = getLoginId();
		
		String requestUrl = ZzbConfiguration.getInstance().getValue(ZzbManageContainer.requestUrl);
		String authCode = zzbService.getInnerAuthCode(custId);

		String redirectUrl = requestUrl + authCode;
		redirectUrl += "&r=" + RandomUtil.randomNumbers(6);
		
		rm.put("redirectUrl", redirectUrl);
		
		return rm.toJson();
	}
	
	@ResponseBody
	@RequestMapping(value = toZhonganCarApi)
	@ApiOperation(notes= toZhonganCarApi,httpMethod = "POST" ,value = "众安车险详情访问授权")
	public String toZhonganCar(){
		
		ResponseModel rm = new ResponseModel();
		String custId = getLoginId();
		
		String url ="https://ztg.zhongan.com/promote/entrance/promoteEntrance.do?redirectType=h5&promotionCode=INST180337743034&productCode=PRD180299655030&promoteCategory=single_product&token=";
		
		String key = ZzbConfiguration.getInstance().getValue(ZzbManageContainer.zhongan_openKey);
		String data = "{\"userID\":\"" + custId + "\"}";
		String sign = RC4Util.encryRC4String(data, key);
		String bizContent = "bizContent=" + sign;
		
		url += "&" + bizContent;
		rm.put("url", url);
		
		return rm.toJson();
	}
	
	@ResponseBody
	@RequestMapping(value = tofanhuaAccidentApi)
	@ApiOperation(notes= tofanhuaAccidentApi,httpMethod = "POST" ,value = "泛华意健险访问授权")
	public String tofanhuaAccident(){
		
		ResponseModel rm = new ResponseModel();
		return rm.toJson();
	}
	
/*	@ResponseBody
	@RequestMapping(value = tomeasureApi)
	@ApiOperation(notes= tomeasureApi,httpMethod = "POST" ,value = "车险测算通知界面")
	public String tomeasure(String id){
		
		ResponseModel rm = new ResponseModel();
		//测试
		String url ="http://www.hdoit.com/ares/wechat/zzb/tomeasure?id="+id;
		//正式
		//String url ="http://www.putiyoli.net/ares/wechat/zzb/tomeasure?id="+id;
		rm.put("url", url);
		return rm.toJson();
	}*/
	
	
}
